import http from "@/utils/request/httpRequest.ts";
import type {ListPagination, ListType} from "@/types/commonType.ts";
import type {
    RoleAddType,
    RoleAssingType,
    RoleHomePageType,
    RoleListType,
    RolePermissionType,
    RoleUpdateType
} from "@/types/RoleType.ts";
import type {UserListType} from "@/types/UserType.ts";

// 角色列表
export const roleListApi = (params: ListPagination & {
    roleName: string
}) => http.get<ListType<RoleListType[]>>('role/getRoleList', {
    params
})

// 角色添加
export const roleAddApi = (data: RoleAddType) => http.post<string>('role/add', data)

// 角色修改
export const roleUpdateApi = (data: RoleUpdateType) => http.post<string>('role/update', data)

// 角色删除
export const roleDeleteApi = (data: {
    id: string
}) => http.post('role/delete', data)

// 分配角色
export const roleAssignApi = (data: RoleAssingType) => http.post('role/assignRoles', data)

// 查询角色用户
export const roleUserApi = (data: ListPagination & {
    id: string
    username: string
}) => http.get<ListType<UserListType[]>>('role/getUsersByRole', {
    params: data
})

// 分配权限
export const rolePermissionApi = (data: RolePermissionType) => http.post<string>('role/assignPermissions', data)

// 查询权限
export const rolePermissionListApi = (data: {
    id: string
}) => http.get<string[]>('role/getPermissionsByRole/' + data.id)

// 角色取消用户关联
export const roleCancelUserApi = (data: {
    roleId: string
    userId: string
}) => http.get('/sys/user/cancelRole', {
    params: data
})
// 角色默认首页
export const roleDefaultHome = (data: RoleHomePageType) => http.post<string>('role/setDefaultHomePage', data)
// 下载导入模版
export const downLoad = (data) => http.get("file/downloadTemplate", {
    responseType: "blob",
    params: data
  })